package SwingForms;

import LogicaClasesNew.Proveedor;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import LogicaClasesNew.ControladorProveedor;
import java.awt.Image;
import javax.swing.ImageIcon;

public class frmInfoProveedor extends javax.swing.JInternalFrame {

    /**
     * Creates new form frmInfoUsuario
     */
    public frmInfoProveedor() {
        initComponents();
        CrearModelo2();
        llenartabla();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JTF_InfoUsuarioMail = new javax.swing.JTextField();
        JL_InfoUsuarioNombreCompania = new javax.swing.JLabel();
        JL_InfoUsuarioNickName = new javax.swing.JLabel();
        JTF_InfoUsuarioNombreCompania = new javax.swing.JTextField();
        JTF_InfoUsuarioNickName = new javax.swing.JTextField();
        JL_InfoUsuarioWeb = new javax.swing.JLabel();
        JL_InfoUsuarioNombre = new javax.swing.JLabel();
        JTF_InfoUsuarioWeb = new javax.swing.JTextField();
        JTF_InfoUsuarioNombre = new javax.swing.JTextField();
        JL_InfoUsuarioApellido = new javax.swing.JLabel();
        JTF_InfoUsuarioApellido = new javax.swing.JTextField();
        JL_InfoUsuarioFechaNacimiento = new javax.swing.JLabel();
        JL_UsuarioMail = new javax.swing.JLabel();
        JL_infoUsuarioInfoUsuario = new javax.swing.JLabel();
        JL_infoUsuarioSeleccioneUsuario = new javax.swing.JLabel();
        JB_InfoProveedorSalir = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtusuarios = new javax.swing.JTable();
        JTF_InfoUsuarioFnacimiento = new javax.swing.JTextField();
        JL_InfoProveedorFoto = new javax.swing.JLabel();

        setResizable(true);
        setTitle("Informacion de Proveedor");
        setToolTipText("");
        setEnabled(false);

        JTF_InfoUsuarioMail.setEditable(false);
        JTF_InfoUsuarioMail.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioMail.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioMail.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JL_InfoUsuarioNombreCompania.setText("*Nombre de Compañia:");

        JL_InfoUsuarioNickName.setText("* NickName:");

        JTF_InfoUsuarioNombreCompania.setEditable(false);
        JTF_InfoUsuarioNombreCompania.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNombreCompania.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNombreCompania.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JTF_InfoUsuarioNickName.setEditable(false);
        JTF_InfoUsuarioNickName.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNickName.setToolTipText("Ingrese un Alias que lo Identificar{a");
        JTF_InfoUsuarioNickName.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNickName.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JL_InfoUsuarioWeb.setText("*Link de Web:");

        JL_InfoUsuarioNombre.setText("* Nombre:");

        JTF_InfoUsuarioWeb.setEditable(false);
        JTF_InfoUsuarioWeb.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioWeb.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioWeb.setDisabledTextColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioWeb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JTF_InfoUsuarioWebActionPerformed(evt);
            }
        });

        JTF_InfoUsuarioNombre.setEditable(false);
        JTF_InfoUsuarioNombre.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNombre.setToolTipText("Ingrese su Nombre");
        JTF_InfoUsuarioNombre.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioNombre.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JL_InfoUsuarioApellido.setText("* Apellido:");

        JTF_InfoUsuarioApellido.setEditable(false);
        JTF_InfoUsuarioApellido.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioApellido.setToolTipText("Ingrese su apellido");
        JTF_InfoUsuarioApellido.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioApellido.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JL_InfoUsuarioFechaNacimiento.setText("*Fecha de Nacimiento:");

        JL_UsuarioMail.setText("*Correo  electronico:");

        JL_infoUsuarioInfoUsuario.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        JL_infoUsuarioInfoUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/InfoProveedorr.png"))); // NOI18N

        JL_infoUsuarioSeleccioneUsuario.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        JL_infoUsuarioSeleccioneUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/seleccioneProveedor.png"))); // NOI18N

        JB_InfoProveedorSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cerrar.png"))); // NOI18N
        JB_InfoProveedorSalir.setToolTipText("Cierra Ventana");
        JB_InfoProveedorSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_InfoProveedorSalirActionPerformed(evt);
            }
        });

        jtusuarios.setForeground(new java.awt.Color(0, 51, 0));
        jtusuarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "N i c k n a m e", "N o m b r e"
            }
        ));
        jtusuarios.setGridColor(new java.awt.Color(51, 102, 0));
        jtusuarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtusuariosMouseClicked(evt);
            }
        });
        jtusuarios.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                jtusuariosComponentMoved(evt);
            }
        });
        jScrollPane1.setViewportView(jtusuarios);
        jtusuarios.getAccessibleContext().setAccessibleName("");

        JTF_InfoUsuarioFnacimiento.setEditable(false);
        JTF_InfoUsuarioFnacimiento.setForeground(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioFnacimiento.setCaretColor(new java.awt.Color(0, 153, 0));
        JTF_InfoUsuarioFnacimiento.setDisabledTextColor(new java.awt.Color(0, 153, 0));

        JL_InfoProveedorFoto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        JL_InfoProveedorFoto.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JL_InfoUsuarioWeb)
                            .addComponent(JL_InfoUsuarioNombreCompania)
                            .addComponent(JL_UsuarioMail)
                            .addComponent(JL_InfoUsuarioFechaNacimiento)
                            .addComponent(JL_InfoUsuarioApellido)
                            .addComponent(JL_InfoUsuarioNombre)
                            .addComponent(JL_InfoUsuarioNickName))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JB_InfoProveedorSalir)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(JTF_InfoUsuarioNombre)
                                .addComponent(JTF_InfoUsuarioApellido)
                                .addComponent(JTF_InfoUsuarioMail)
                                .addComponent(JTF_InfoUsuarioNombreCompania)
                                .addComponent(JTF_InfoUsuarioWeb, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(JTF_InfoUsuarioNickName, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(JTF_InfoUsuarioFnacimiento, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(JL_infoUsuarioInfoUsuario))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(JL_infoUsuarioSeleccioneUsuario))
                        .addGap(18, 18, 18)
                        .addComponent(JL_InfoProveedorFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 51, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(JL_infoUsuarioSeleccioneUsuario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(JL_InfoProveedorFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addComponent(JL_infoUsuarioInfoUsuario)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioNickName)
                    .addComponent(JTF_InfoUsuarioNickName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioNombre)
                    .addComponent(JTF_InfoUsuarioNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioApellido)
                    .addComponent(JTF_InfoUsuarioApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioFechaNacimiento)
                    .addComponent(JTF_InfoUsuarioFnacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_UsuarioMail)
                    .addComponent(JTF_InfoUsuarioMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioNombreCompania)
                    .addComponent(JTF_InfoUsuarioNombreCompania, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_InfoUsuarioWeb)
                    .addComponent(JTF_InfoUsuarioWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(JB_InfoProveedorSalir)
                .addContainerGap())
        );

        JTF_InfoUsuarioNickName.getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //CERRAR
    private void JB_InfoProveedorSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_InfoProveedorSalirActionPerformed
        //Oculta formulario
        this.setVisible (false);
    }//GEN-LAST:event_JB_InfoProveedorSalirActionPerformed

    private void jtusuariosComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jtusuariosComponentMoved
        // TODO add your handling code here:
    }//GEN-LAST:event_jtusuariosComponentMoved

    private void jtusuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtusuariosMouseClicked
        // TODO add your handling code here:
        try {
            int row= jtusuarios.getSelectedRow();
            String nick=(jtusuarios.getModel().getValueAt(row, 0).toString());
            
            //EntityManagerFactory emf = Persistence.createEntityManagerFactory("Persistencia");
            //EntityManager em = emf.createEntityManager();
            ControladorProveedor jpapro = new ControladorProveedor(); 
            Proveedor proveedor = jpapro.findProveedor (nick);
            JTF_InfoUsuarioNickName.setText(proveedor.getNickname());
            JTF_InfoUsuarioNombre.setText(proveedor.getNombre());
            JTF_InfoUsuarioApellido.setText(proveedor.getApellido());
            JTF_InfoUsuarioMail.setText(proveedor.getMail());
            JTF_InfoUsuarioNombreCompania.setText(proveedor.getCompania());
            JTF_InfoUsuarioWeb.setText(proveedor.getWeb());
            JTF_InfoUsuarioFnacimiento.setText(proveedor.getFechNacim());
            
            if (proveedor.getFoto() != null){
                
                ImageIcon foto = new ImageIcon( proveedor.getFoto() );
                Image img = foto.getImage(); //convertimos icon en una imagen
                Image otraimg = img.getScaledInstance(135, 135, java.awt.Image.SCALE_SMOOTH ); 
                ImageIcon otroicon = new ImageIcon( otraimg );

                JL_InfoProveedorFoto.setIcon(otroicon);
            }else{
                JL_InfoProveedorFoto.setIcon(null);
            }//FIN de if
            
        } catch (Exception e) {
            getToolkit().beep();
            JOptionPane.showMessageDialog(this, "ERROR \n" + e , "Error" , JOptionPane.ERROR_MESSAGE);
        }
        
        
    }//GEN-LAST:event_jtusuariosMouseClicked

    private void JTF_InfoUsuarioWebActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JTF_InfoUsuarioWebActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JTF_InfoUsuarioWebActionPerformed
    private void llenartabla (){
        ControladorProveedor jpapro = new ControladorProveedor();    
        
        
        try {
            Object A[] = null;
            List<Proveedor> ListaProveedores;
            ListaProveedores= jpapro.findProveedorEntities();
            for (int i = 0; i < ListaProveedores.size(); i++) {
                modelo2.addRow(A);
                modelo2.setValueAt(ListaProveedores.get(i).getNickname(), i, 0);
                modelo2.setValueAt(ListaProveedores.get(i).getMail(), i, 1);
                
            }
        }
        catch (Exception e){
            getToolkit().beep();
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
    }
    
    
     public static DefaultTableModel modelo2;
     
     private void CrearModelo2(){
         try {
             modelo2 = (new DefaultTableModel(
                null, new String [] {
                "Nickname","Correo Electronico"}){
                Class[] types = new Class [] {
                java.lang.String.class,
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false,false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          jtusuarios.setModel(modelo2);
         } catch (Exception e) {
             getToolkit().beep();
             JOptionPane.showMessageDialog(null,e.toString()+"error2");
            }    
     }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_InfoProveedorSalir;
    private javax.swing.JLabel JL_InfoProveedorFoto;
    private javax.swing.JLabel JL_InfoUsuarioApellido;
    private javax.swing.JLabel JL_InfoUsuarioFechaNacimiento;
    private javax.swing.JLabel JL_InfoUsuarioNickName;
    private javax.swing.JLabel JL_InfoUsuarioNombre;
    private javax.swing.JLabel JL_InfoUsuarioNombreCompania;
    private javax.swing.JLabel JL_InfoUsuarioWeb;
    private javax.swing.JLabel JL_UsuarioMail;
    private javax.swing.JLabel JL_infoUsuarioInfoUsuario;
    private javax.swing.JLabel JL_infoUsuarioSeleccioneUsuario;
    private javax.swing.JTextField JTF_InfoUsuarioApellido;
    private javax.swing.JTextField JTF_InfoUsuarioFnacimiento;
    private javax.swing.JTextField JTF_InfoUsuarioMail;
    private javax.swing.JTextField JTF_InfoUsuarioNickName;
    private javax.swing.JTextField JTF_InfoUsuarioNombre;
    private javax.swing.JTextField JTF_InfoUsuarioNombreCompania;
    private javax.swing.JTextField JTF_InfoUsuarioWeb;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jtusuarios;
    // End of variables declaration//GEN-END:variables
}
